package com.smart.campus.web.controller.school;

import java.util.List;

import com.smart.campus.web.utils.SchoolUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.smart.campus.common.annotation.Log;
import com.smart.campus.common.enums.BusinessType;
import com.smart.campus.school.domain.IllegalType;
import com.smart.campus.school.service.IIllegalTypeService;
import com.smart.campus.common.core.controller.BaseController;
import com.smart.campus.common.core.domain.AjaxResult;
import com.smart.campus.common.utils.poi.ExcelUtil;
import com.smart.campus.common.core.page.TableDataInfo;

/**
 * 违规记录类型Controller
 * 
 * @author Zhihe.Li
 * @date 2020-05-25
 */
@Controller
@RequestMapping("/school/illegalType")
public class IllegalTypeController extends BaseController
{
    private String prefix = "school/illegalType";

    @Autowired
    private IIllegalTypeService illegalTypeService;

    @RequiresPermissions("school:illegalType:view")
    @GetMapping()
    public String illegalType()
    {
        return prefix + "/illegalType";
    }

    /**
     * 查询违规记录类型列表
     */
    @RequiresPermissions("school:illegalType:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IllegalType illegalType)
    {
        startPage();
        illegalType.setSchoolId(SchoolUtil.getSchoolId());
        List<IllegalType> list = illegalTypeService.selectIllegalTypeList(illegalType);
        return getDataTable(list);
    }

    /**
     * 导出违规记录类型列表
     */
    @RequiresPermissions("school:illegalType:export")
    @Log(title = "违规记录类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IllegalType illegalType)
    {
        illegalType.setSchoolId(SchoolUtil.getSchoolId());
        List<IllegalType> list = illegalTypeService.selectIllegalTypeList(illegalType);
        ExcelUtil<IllegalType> util = new ExcelUtil<IllegalType>(IllegalType.class);
        return util.exportExcel(list, "illegalType");
    }

    /**
     * 新增违规记录类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存违规记录类型
     */
    @RequiresPermissions("school:illegalType:add")
    @Log(title = "违规记录类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IllegalType illegalType)
    {
        illegalType.setSchoolId(SchoolUtil.getSchoolId());
        return toAjax(illegalTypeService.insertIllegalType(illegalType));
    }

    /**
     * 修改违规记录类型
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        IllegalType illegalType = illegalTypeService.selectIllegalTypeById(id);
        mmap.put("illegalType", illegalType);
        return prefix + "/edit";
    }

    /**
     * 修改保存违规记录类型
     */
    @RequiresPermissions("school:illegalType:edit")
    @Log(title = "违规记录类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IllegalType illegalType)
    {
        return toAjax(illegalTypeService.updateIllegalType(illegalType));
    }

    /**
     * 删除违规记录类型
     */
    @RequiresPermissions("school:illegalType:remove")
    @Log(title = "违规记录类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(illegalTypeService.deleteIllegalTypeByIds(ids));
    }
}
